package com.xcity.game.combat.skill.impl;

import com.alibaba.fastjson.annotation.JSONField;
import com.xcity.game.combat.Action;
import com.xcity.game.combat.ActionEffect;
import com.xcity.game.combat.CombatUtils;
import com.xcity.game.combat.attr.CombatAttributeType;
import com.xcity.game.combat.buff.CombatBuff;
import com.xcity.game.combat.skill.CombatSkill;
import com.xcity.game.combat.unit.CombatUnit;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.skill.Skill;
import com.xcity.game.skill.template.SkillTemplate;

/**
 * 雾里看花<br/>
 * 随机降低敌方一名敌人的速度值{0=30#0}%
 * @author yang.li
 *
 */
public class COMBAT_SKILL_90086 extends CombatSkill {

	public COMBAT_SKILL_90086(Skill skill) {
		super(skill);
	}

	@Override
	public void calcDamage(Action action) {
		CombatUnit target = action.target.getUnitRandomly();
		if (target != null) {
			// 100%伤害
			ActionEffect effect = action.addTarget(target);
			target = effect.getUnit(); // 修正目标
//			int damage = CombatUtils.calcCommonMagicDamage(action.unit, target);
//			effect.effect(CombatAttributeType.HP, -damage);
			CombatUtils.calcMagicAttack(effect);
			// debuff
			action.addBuff(new BUFF(skill, target));
		}
	}
	
	static class BUFF extends CombatBuff {
		public BUFF(Skill skill, CombatUnit owner) {
			super(skill.getTemplate().getCombatBuff(), owner);
			active = true;
			int speed = owner.getAttackSpeed();
			int speedDelta = (int) (speed * skill.getParameter(0) / GameStaticConfig.percentBase);
			owner.setAttributeValue(CombatAttributeType.ATTACK_SPEED, speed - speedDelta);
		}
		@Override
		@JSONField(serialize = false)
		public boolean isDebuff() {
			return true;
		}
	}

}
